//
//  FFWithdrawAmountInputCell.m
//  LLWallet
// 提现金额输入cell
//  Created by tt on 2020/9/16.
//

#import "FFWithdrawAmountInputCell.h"

@implementation FFWithdrawAmountInputModel

- (Class)cell {
    return FFWithdrawAmountInputCell.class;
}

- (NSNumber *)showArrow {
    return @(false);
}
@end

@interface FFWithdrawAmountInputCell ()

@property(nonatomic,strong) UILabel *withdrawTipLbl; // 提现tip
@property(nonatomic,strong) UILabel *walletAmountLbl; // 钱包金额
@property(nonatomic,strong) UILabel *unitLbl; // 钱单位
@property(nonatomic,strong) UITextField *amountFd; // 提现金额输入

@property(nonatomic,strong) UIButton *allWithdrawBtn; // 全部提现的按钮

@property(nonatomic,strong) FFWithdrawAmountInputModel *model;

@end

@implementation FFWithdrawAmountInputCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 100.0f);
}

- (void)setupUI {
    [super setupUI];
    [self.contentView addSubview:self.withdrawTipLbl];
    [self.contentView addSubview:self.unitLbl];
    [self.contentView addSubview:self.walletAmountLbl];
    [self.contentView addSubview:self.amountFd];
    [self.contentView addSubview:self.allWithdrawBtn];
}

- (void)refresh:(FFWithdrawAmountInputModel *)model {
    [super refresh:model];
    self.model = model;
    self.walletAmountLbl.text = model.remark;
    self.amountFd.text = model.value;
}


- (UILabel *)withdrawTipLbl {
    if(!_withdrawTipLbl) {
        _withdrawTipLbl = [[UILabel alloc] init];
        _withdrawTipLbl.textColor = [WKApp shared].config.tipColor;
        [_withdrawTipLbl setFont:[[WKApp shared].config appFontOfSize:14.0f]];
        _withdrawTipLbl.text = LLang(@"提现金额");
        [_withdrawTipLbl sizeToFit];
    }
    return _withdrawTipLbl;
}

- (UILabel *)walletAmountLbl {
    if(!_walletAmountLbl) {
        _walletAmountLbl = [[UILabel alloc] init];
        _walletAmountLbl.textColor = [WKApp shared].config.tipColor;
        [_walletAmountLbl setFont:[[WKApp shared].config appFontOfSize:12.0f]];
    }
    return _walletAmountLbl;
}

- (UILabel *)unitLbl {
    if(!_unitLbl) {
        _unitLbl = [[UILabel alloc] init];
        [_unitLbl setFont:[[WKApp shared].config appFontOfSizeMedium:20.0f]];
        _unitLbl.text = @"¥";
        [_unitLbl sizeToFit];
    }
    return _unitLbl;
}

- (UITextField *)amountFd {
    if(!_amountFd) {
        _amountFd = [[UITextField alloc] init];
        [_amountFd setBackgroundColor:[UIColor clearColor]];
        [_amountFd setPlaceholder:@"0.00"];
        [_amountFd setFont:[[WKApp shared].config appFontOfSizeSemibold:24.0f]];
        [_amountFd addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];
        [_amountFd setKeyboardType:UIKeyboardTypeNumberPad];
    }
    return _amountFd;
}

-(void) textChange {
    if(self.model.onChange) {
        self.model.onChange(self.amountFd.text);
    }
}

- (UIButton *)allWithdrawBtn {
    if(!_allWithdrawBtn) {
        _allWithdrawBtn = [[UIButton alloc] init];
        [_allWithdrawBtn setTitle:LLang(@"全部提现") forState:UIControlStateNormal];
        [[_allWithdrawBtn titleLabel] setFont:[[WKApp shared].config appFontOfSize:12.0f]];
        [_allWithdrawBtn setTitleColor:[WKApp shared].config.themeColor forState:UIControlStateNormal];
        [_allWithdrawBtn sizeToFit];
        [_allWithdrawBtn addTarget:self action:@selector(allWithdrawBtnPressed) forControlEvents:UIControlEventTouchUpInside];
    }
    return _allWithdrawBtn;
}

-(void) allWithdrawBtnPressed {
    if(self.model.onAllWithdraw) {
        self.model.onAllWithdraw();
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.withdrawTipLbl.lim_left = 15.0f;
    self.withdrawTipLbl.lim_top = 10.0f;
    
    self.unitLbl.lim_left = self.withdrawTipLbl.lim_left;
    self.unitLbl.lim_top = self.lim_height/2.0f - self.unitLbl.lim_height/2.0f;
    
    self.amountFd.lim_left = self.unitLbl.lim_right + 4.0f;
    self.amountFd.lim_height = 40.0f;
    self.amountFd.lim_top = self.lim_height/2.0f - self.amountFd.lim_height/2.0f;
    self.amountFd.lim_width = self.lim_width - self.amountFd.lim_left*2.0f;
    
    [self.walletAmountLbl sizeToFit];
    self.walletAmountLbl.lim_top =  self.amountFd.lim_bottom + 4.0f;
    self.walletAmountLbl.lim_left = self.withdrawTipLbl.lim_left;
    
    self.allWithdrawBtn.lim_left = self.walletAmountLbl.lim_right +4.0f;
    self.allWithdrawBtn.lim_top = self.walletAmountLbl.lim_top + (self.walletAmountLbl.lim_height/2.0f - self.allWithdrawBtn.lim_height/2.0f);
    
}

@end
